package com.joker.web.controller.orange;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.joker.common.annotation.RepeatSubmit;
import com.joker.common.annotation.Log;
import com.joker.common.core.controller.BaseController;
import com.joker.common.core.domain.PageQuery;
import com.joker.common.core.domain.R;
import com.joker.common.core.validate.AddGroup;
import com.joker.common.core.validate.EditGroup;
import com.joker.common.enums.BusinessType;
import com.joker.common.utils.poi.ExcelUtil;
import com.joker.orange.domain.vo.LongVideoCategoryVo;
import com.joker.orange.domain.bo.LongVideoCategoryBo;
import com.joker.orange.service.ILongVideoCategoryService;
import com.joker.common.core.page.TableDataInfo;

/**
 * 长视频分类
 *
 * @author Joker
 * @date 2024-06-09
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/resource/category")
public class LongVideoCategoryController extends BaseController {

    private final ILongVideoCategoryService iLongVideoCategoryService;

    /**
     * 查询长视频分类列表
     */
    @SaCheckPermission("resource:category:list")
    @GetMapping("/list")
    public TableDataInfo<LongVideoCategoryVo> list(LongVideoCategoryBo bo, PageQuery pageQuery) {
        return iLongVideoCategoryService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询全部分类
     */
    @GetMapping("/listAllCategory")
    public R<List<LongVideoCategoryVo>> listAllCategory(){
        LongVideoCategoryBo bo = new LongVideoCategoryBo();
        bo.setVisible("0");
        return R.ok(iLongVideoCategoryService.queryList(bo));
    }

    /**
     * 导出长视频分类列表
     */
    @SaCheckPermission("resource:category:export")
    @Log(title = "长视频分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LongVideoCategoryBo bo, HttpServletResponse response) {
        List<LongVideoCategoryVo> list = iLongVideoCategoryService.queryList(bo);
        ExcelUtil.exportExcel(list, "长视频分类", LongVideoCategoryVo.class, response);
    }

    /**
     * 获取长视频分类详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("resource:category:query")
    @GetMapping("/{id}")
    public R<LongVideoCategoryVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iLongVideoCategoryService.queryById(id));
    }

    /**
     * 新增长视频分类
     */
    @SaCheckPermission("resource:category:add")
    @Log(title = "长视频分类", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LongVideoCategoryBo bo) {
        return toAjax(iLongVideoCategoryService.insertByBo(bo));
    }

    /**
     * 修改长视频分类
     */
    @SaCheckPermission("resource:category:edit")
    @Log(title = "长视频分类", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LongVideoCategoryBo bo) {
        return toAjax(iLongVideoCategoryService.updateByBo(bo));
    }

    /**
     * 删除长视频分类
     *
     * @param ids 主键串
     */
    @SaCheckPermission("resource:category:remove")
    @Log(title = "长视频分类", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iLongVideoCategoryService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
